﻿using DevExpress.XtraEditors;
using DXApplicationTangche.UC.nlp.service;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.nlp
{
    public partial class FormNlp上传文件 : DevExpress.XtraEditors.XtraForm
    {
        public FormNlp上传文件()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.textBoxmeta.Text))
            {
                return;
            }
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "请选择文件";
            ofd.Filter = "(*xlsx;*.xls;*.docx;*.doc;*.pdf)|*xlsx;*.xls;*.docx;*.doc;*.pdf";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                String fileName;
                //  如果为.doc需要先转为.docx
                if (Path.GetExtension(ofd.FileName).Equals(".doc"))
                {
                    fileName = FileUtil.ConvertDocToDocx(ofd.FileName);
                }
                else
                {
                    fileName = ofd.FileName;
                }
                //  文件上传
                String re = NlpService.uploadFile(this.textBoxmeta.Text.Trim(), fileName);
                MessageBox.Show(re);
            }
        }

        private void simpleButtonExcel转pdf_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "请选择文件";
            ofd.Filter = "(*xlsx;*.xls;*.docx;*.doc;*.pdf)|*xlsx;*.xls;*.docx;*.doc;*.pdf";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                String fileName;
                //  如果为.doc需要先转为.docx
                if (Path.GetExtension(ofd.FileName).Equals(".xlsx") || Path.GetExtension(ofd.FileName).Equals(".xls"))
                {
                    String _lstrOutFile = "F:\\新建文件夹\\222111.pdf";
                    Boolean re = FileUtil.ConverterToPdf(ofd.FileName, _lstrOutFile);
                    Boolean ret = re;
                }
                else
                {
                    fileName = ofd.FileName;
                }
            }
        }
        
    }
}